package d3_charset;

import sun.nio.cs.ext.GBK;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

public class t1 {
    public static void main(String[] args) {
        String data="a我m";
        byte[] bytes=data.getBytes();//编码UTF-8
        System.out.println(Arrays.toString(bytes));

        //按照指定字符集进行编码
        try {
            byte[] bytes1=data.getBytes("GBK");
            System.out.println(Arrays.toString(bytes1));
            String s2=new String(bytes1,"GBK");
            System.out.println(s2);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
        String s1=new String(bytes);//解码
        System.out.println(s1);
    }
}
